/*
 * Copyright (C) 2012 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * This code is not supported by Google
 *
 */

package com.google.enterprise.gsa.commerce;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;

public class Result  implements Iterable<Product> {

	private float elapsed_time;
	private String query;
	private int totalResults;
	private HashMap<String, String> query_params = new HashMap<String, String>();
	private Vector<Product> products = new Vector<Product>();
	private Vector<Facet> facets = new Vector<Facet>();
	private Vector<String> spelling_suggestions = new Vector<String>();
	private ArrayList<HashMap<String,String>> keymatchs = new ArrayList<HashMap<String,String>>();
	private ArrayList<OneBoxResult> oneboxresults = new ArrayList<OneBoxResult>();
	private ArrayList<String> restricts = new   ArrayList<String>();
	
	public static String KEYMATCH_TITLE = "title";
	public static String KEYMATCH_URL = "url";
	
	@Override
	public Iterator<Product> iterator() {
	   return products.iterator();
	}
	
	public boolean has_keymatches()
	{
		return !keymatchs.isEmpty();
	}
	
	public boolean has_oneboxresults()
	{
		return !oneboxresults.isEmpty();
	}
	
	public void addOneBoxResult(OneBoxResult obr)
	{
		this.oneboxresults.add(obr);
	}
	
	public ArrayList<OneBoxResult> getOneBoxResults()
	{
		return this.oneboxresults;
	}
	
	public void addKeyMatch(String title, String url)
	{
		HashMap<String,String> hm_km = new HashMap<String,String>();
		hm_km.put(Result.KEYMATCH_TITLE, title);
		hm_km.put(Result.KEYMATCH_URL, url);
		keymatchs.add(hm_km);
	}	
	
	public ArrayList<HashMap<String,String>> getKeyMatches()
	{
		return keymatchs;
	}

	public boolean has_spelling_suggestions()
	{
		return !spelling_suggestions.isEmpty();
	}
	
	public void addSpellingSuggestion(String spelling_suggestion)
	{
		this.spelling_suggestions.add(spelling_suggestion);
	}
	
	public Vector<String> getSpellingSuggestions()
	{
		return this.spelling_suggestions;
	}
	
	public void setElapsedTime(float elapsed_time) {
		this.elapsed_time = elapsed_time;
	}
	
	public float getElapsedTime() {
		return this.elapsed_time;
	}	
		
	public void setQuery(String query) {
		this.query = query;
	}
	
	public String getQuery() {
		return this.query;
	}
	
	public void addProduct(Product p) {
		products.add(p);
	}
	
	public Vector<Product> getProducts() {
		return this.products;
	}
	
	public void addFacet(Facet f) {
		facets.add(f);
	}
	
	public Vector<Facet> getFacets() {
		return this.facets;
	}	
	
	
	public void setTotalResults(int totalResults) {
		this.totalResults = totalResults;
	}
	
	public int getTotalResults() {
		return this.totalResults;
	}
	
	public void addQueryParam(String param, String value) {
		this.query_params.put(param, value);
	}
	
	public HashMap<String,String> getQueryParams() {
		return this.query_params;
	}	
	
	public void addRestrict(String s) {
		this.restricts.add(s);
	}

	public ArrayList<String> getRestricts() {
		return this.restricts;
	}

}